﻿
using OABLL;
using OAModel;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MyOA
{
    public partial class UserSetUp : Form
    {
        shengbll Shengbll=new shengbll();

        shibll Shibll=new shibll();

        usersetupbll bll = new usersetupbll();

        public string _yuangongid = string.Empty;

        public UserSetUp(string oa)
        {
            InitializeComponent();
            _yuangongid=oa;
        }

        private void UserSetUp_Load(object sender, EventArgs e)
        {
           
            // TODO: 这行代码将数据加载到表“oadbDataSet1.省”中。您可以根据需要移动或移除它。
            this.省TableAdapter.Fill(this.oadbDataSet1.省);


            OAUseEntity user = new OAUseBLL().Getyuangong(_yuangongid);
            this.lbl员工id.Text = user.Oa员工id;
            this.lbl员工姓名.Text = user.Oa姓名;


        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        //修改
        private void button2_Click(object sender, EventArgs e)
        {


            //非空验证
            if (密码1.Text.Trim() != "" && 密码2.Text.Trim() != "")
            {
                UserEntity user = new UserEntity();
                user.Oa姓名=this.lbl员工姓名.Text;
                user.Oa员工id = this.lbl员工id.Text;
                
                string ymm = 密码1.Text.Trim();

                if (bll.quedingmima(user,ymm)) { 

                   

                if (密码2.Text.Trim() != 密码1.Text.Trim())
                {
                    user.Oa密码=密码2.Text.Trim();
                    user.Oa电话=tel.Text.Trim();
                    user.Oa省编号=省.Text.Trim();
                    user.Oa市编号 = 市.Text.Trim();
                    user.Oa区编号=区.Text.Trim();
                    if (省.SelectedValue != null)
                    {
                        user.Oa省编号 = 省.SelectedValue.ToString();
                    }
                    else
                    {
                        MessageBox.Show("请选择省份！");
                    }

                    if (市.SelectedValue != null)
                    {
                        user.Oa市编号 = 市.SelectedValue.ToString();
                    }
                    else
                    {
                        MessageBox.Show("请选择城市！");
                    }

                    if (区.SelectedValue != null)
                    {

                        user.Oa区编号 = 区.SelectedValue.ToString();
                    }
                    else
                    {
                        MessageBox.Show("请选择所在区！");
                    }
                }
                else
                {
                    MessageBox.Show("两次密码一致，请重新输入!");
                    this.密码1.Focus();//把鼠标的光标直接定位到 密码框上 
                }

                bool bl = bll.AddOAUser(user);
                if (bl == true)
                {
                    MessageBox.Show("修改成功");
                  this.Close();
                       Application.Restart();
                    }
                else
                {
                    MessageBox.Show("修改失败！请稍后再试");

                }

                }
                else
                {
                    MessageBox.Show("原密码错误，请重新输入");
                }
            }

        }


        


        
        private void 省_SelectedIndexChanged_1(object sender, EventArgs e)
        {
            if (省.SelectedValue != null) { 

            string sid = 省.SelectedValue.ToString();
            DataSet ds = Shengbll.GetCitylist(sid);
            市.DisplayMember = "市名称";
            市.ValueMember = "市编号";

            市.DataSource = ds.Tables[0];
            }
        }

        private void 市_SelectedIndexChanged_1(object sender, EventArgs e)
        {


            区.DataSource = Shibll.GetQuByShiId(this.市.SelectedValue.ToString()).Tables[0];

        }
    }
    }

